import { Permission, User } from '@/types'

/**
 * 检查用户是否有指定权限
 */
export function hasPermission(user: User | null, permission: Permission | Permission[]): boolean {
  if (!user) return false
  
  // 管理员拥有所有权限
  if (user.role === 'admin') return true
  
  const permissions = Array.isArray(permission) ? permission : [permission]
  
  return permissions.some(p => user.permissions.includes(p))
}

/**
 * 检查用户是否有任一权限
 */
export function hasAnyPermission(user: User | null, permissions: Permission[]): boolean {
  if (!user) return false
  if (user.role === 'admin') return true
  
  return permissions.some(p => user.permissions.includes(p))
}

/**
 * 检查用户是否有所有权限
 */
export function hasAllPermissions(user: User | null, permissions: Permission[]): boolean {
  if (!user) return false
  if (user.role === 'admin') return true
  
  return permissions.every(p => user.permissions.includes(p))
}

